<?php
/**
 * Created by PhpStorm.
 * User: Jerry
 * Date: 2017/2/17
 * Time: 15:23
 */

namespace SDXApi\Model;


use Think\Model;

/**
 * Class SeminarPageSeminarModel
 * @package SDXApi\Model
 */
class SeminarPageSeminarModel extends Model
{
	/**
	 * @var string
	 */
	protected $tableName = 'seminar_template_pages_seminar';

	/**
	 * Created by Jerry
	 * @param $page_id
	 * @return mixed
	 */
	public function findSeminarPageSeminarByPageId($page_id)
	{
		$time = time();
		$where = array(
			'ss.page_id'	=>	$page_id,
			'st.`status`'	=>	1,
			'st.start_time'	=>	array('LT', $time,),
			'st.end_time'	=>	array('GT', $time,),
			'st.image'		=>	array('NEQ', ''),
		);

		$field = 'st.id,st.`name`,st.image,st.`desc`';

		$data = $this
				->field($field)
				->alias('ss')
				->join('LEFT JOIN __SEMINAR_TEMPLATES__ AS st ON ss.seminar_id = st.id')
				->where($where)
				->group('ss.seminar_id')
				->order('ss.sort DESC')
				->select();
		return $data;
	}
}